/*
 * LogoMatcher.cpp
 *
 *  Created on: 01/07/2011
 *      Author: fellipe
 */


#include "LogoMatcher.h"

LogoMatcher::LogoMatcher( int argc, char** argv) {


	/*vector<char *> paths = vector<char *>();
	//paths.push_back("./logos/teste/coca.jpg");
	//paths.push_back("./logos/teste/ubuntu.jpg");
	paths.push_back("./logos/banco/opensuse.jpg");
	//paths.push_back("./logos/banco/chrome.jpg");
	paths.push_back("./logos/probes/probe2.jpg");

	printf("############################################\n");*/
	printf("Carregando a Base de %d logos!\n",argc-1);
	for (int i = 1; i < argc; ++i) {
		my::SIFT *template1 = loadImage(argv[i]);
		template1->handle += i+'1';
		template1->ShowKeypoints();		// Show the keypoints
		//template1->printKeypointsFV();		// Show the keypointsDescriptors
		templatesDB.push_back(template1);
	};
	printf("############################################\n");

	//templatesDB[0]->compara(templatesDB[1]);

	for (int i = 0; i < templatesDB.size()-1; i++) {
		printf("Comparando %s com %s",argv[i],argv[templatesDB.size()-1]);
		templatesDB[i]->compara(templatesDB[templatesDB.size()-1]);
	};

}

my::SIFT * LogoMatcher::loadImage(char *path){
	printf("*\t Carregando:%s\n",path);
	my::SIFT * template1 = new my::SIFT(path, 8, 4,0.7);
	string buf = path;
	template1->handle = buf;
	template1->DoSift();				// Find keypoints
	//template1->ShowAbsSigma();		// Display the sigma table
	return template1;
}

void LogoMatcher::matchLogos(char *probePath){
	my::SIFT * probe = loadImage(probePath);
	for (int i = 0; i < templatesDB.size(); ++i) {
		// deveria se algo do tipo ( acha template)
		probe->compara(templatesDB[i]);

		//so o primeiro por enquanto
		break;

	}
}


LogoMatcher::~LogoMatcher() {
	// TODO Auto-generated destructor stub
}
int main( int argc, char** argv )
{
	if (argc == 1){

		printf("Syntax error:\n \t Try: %s pathToLogo1 pathToLogo2 ... pathToLogon pathToMatchImage",argv[0]);
		printf("\n\t All logos will be detected on the \"image to match\"!!!!");
		printf("\n\t Example: %s logo1.jpg image.jpg \n\t\t Will try to detect logo1 on image.",argv[0]);
		exit(0);
	}

	LogoMatcher matcher = LogoMatcher(argc, argv);
	cvWaitKey();


	return 0;
}
